package cn.rxls.community.strategy.bill;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 账单策略工厂
 */
@Component
public class BillStrategyFactory {

    //策略存储集合
    public final static Map<String, BillStrategy> BILL_SERVICE_MAP = new ConcurrentHashMap<>();


    /**
     * 注册策略--初始化
     */
    public static void register(String type, BillStrategy handler) {
        if (handler == null && Objects.isNull(type) || type.equals("")) {
            return;
        }
        BILL_SERVICE_MAP.put(type, handler);
    }

    /**
     * 根据类型获取策略
     */
    public static BillStrategy getStrategy(String type) {
        if(Objects.isNull(type) || type.equals("") ){
            return null;
        }
       return BILL_SERVICE_MAP.get(type);
    }
}
